home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / C Internet Config / IC Application Source ƒ / Build 'ThNg' ƒ / DSUserProcs.c < prev    next >
Encoding:
Text File  |  1995-12-05  |  13.9 KB  |  187 lines  |  [TEXT/SPM ]

  1. /******************************************************************************
  2. **
  3. **  Project Name:    DropShell
  4. **     File Name:    DSUserProcs.c
  5. **
  6. **   Description:    Specific AppleEvent handlers used by the DropBox
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **    MTC            Marshall Clow
  16. **    SCS            Stephan Somogyi
  17. **
  18. *******************************************************************************
  19. **                      R E V I S I O N   H I S T O R Y
  20. *******************************************************************************
  21. **
  22. **      Date        Time    Author    Description
  23. **    --------    -----    ------    ---------------------------------------------
  24. **    06/23/94            LDR        Added support for ProcessItem and ProcessFolder handling
  25. **    02/20/94            LDR        Modified Preflight & Postflight to take item count
  26. **    01/25/92            LDR        Removed the use of const on the userDataHandle
  27. **    12/09/91            LDR        Added the new SelectFile userProc
  28. **                                Added the new Install & DisposeUserGlobals procs
  29. **                                Modified PostFlight to only autoquit on odoc, not pdoc
  30. **    11/24/91            LDR        Added the userProcs for pdoc handler
  31. **                                Cleaned up the placement of braces
  32. **                                Added the passing of a userDataHandle
  33. **    10/29/91            SCS        Changes for THINK C 5
  34. **    10/28/91            LDR        Officially renamed DropShell (from QuickShell)
  35. **                                Added a bunch of comments for clarification
  36. **    10/06/91    00:02    MTC        Converted to MPW C
  37. **    04/09/91    00:02    LDR        Added to Projector
  38. **
  39. ******************************************************************************/
  40.  
  41. #include <StandardFile.h>
  42.  
  43. #include "DSGlobals.h"
  44. #include "DSUserProcs.h"
  45.  
  46. // Static Prototypes
  47. static OSErr ProcessItem(FSSpecPtr myFSSPtr);
  48. static OSErr ProcessFolder(FSSpecPtr myFSSPtr);
  49.  
  50.  
  51. /*
  52.     Uncomment this line if you want each item of a dropped folder processea real index
  53.             cipb.hFileInfo.ioDirID        = dirID;
  54.             err = PBGetCatInfoSync(&cipb);
  55.  
  56.             if (!err) {
  57.                 BlockMoveData(fName, curFSSpec.name, 32);
  58.                 curFSSpec.vRefNum    = cipb.hFileInfo.ioVRefNum;
  59.                 curFSSpec.parID        = dirID;
  60.             
  61.                 /*    
  62.                     Check to see if this entry is a folder.
  63.                 */
  64.                 if (cipb.hFileInfo.ioFlAttrib & ioDirMask) {
  65.                     err = ProcessFolder(&curFSSpec);
  66.                  } else
  67.                     err = ProcessItem(&curFSSpec);
  68.             
  69.                 /*    If we've had an error, get out! */
  70.                 if (err)    break;
  71.  
  72.                 // dirID = origDirID;    
  73.                 localIndex = index;    
  74.  
  75.                 /*    
  76.                     Now take into account new files being created
  77.                     in the current directory & messing up our index.
  78.                     See Dev.CD Vol. XI:Tools & Apps (Moof!):Misc Utilities:
  79.                     Disinfectant & Source 2.5.1:Sample:Notes:Scan Alg    
  80.                 */
  81.                 vFName [0] = 0;
  82.                 cipb.hFileInfo.ioCompletion    = 0L;
  83.                 cipb.hFileInfo.ioNamePtr    = vFName;
  84.                 cipb.hFileInfo.ioVRefNum    = localFSSpec.vRefNum;
  85.                 cipb.hFileInfo.ioFDirIndex    = localIndex;    // use a real index
  86.                 cipb.hFileInfo.ioDirID        = dirID;
  87.                 err = PBGetCatInfoSync(&cipb);
  88.                 oldIndex = index;
  89.                 if (!err) {
  90.                     /*    If they're equal - same place, go to next */
  91.                     if (EqualString (vFName, fName, false, false))
  92.                         index++;
  93.                 }
  94.                 
  95.                 /*    If we didn't advance, then perhaps a file was created or deleted */
  96.                 if (oldIndex == index) {
  97.                     oldIndex        = index;    /* save off the old */
  98.                     index            = 0;        /* and start at the beginning */
  99.                     err                = noErr;
  100.                     vFName [0]        = 0;
  101.                     foundPosition    = false;
  102.                     
  103.                     while (!foundPosition) {
  104.                         index++;
  105.                         vFName [0] = 0;
  106.                         cipb.hFileInfo.ioCompletion    = 0L;
  107.                         cipb.hFileInfo.ioNamePtr    = vFName;
  108.                         cipb.hFileInfo.ioVRefNum    = localFSSpec.vRefNum;
  109.                         cipb.hFileInfo.ioFDirIndex    = index;    /* now use a real index */
  110.                         cipb.hFileInfo.ioDirID        = dirID;
  111.                         err = PBGetCatInfoSync(&cipb);
  112.                         
  113.                         if (err == fnfErr) {  // we've just been deleted
  114.                             index = oldIndex;
  115.                             foundPosition = true;
  116.                             err = noErr;    // have to remember to reset this!
  117.                         }
  118.                         
  119.                     /*    found same file & same index position */
  120.                     /*    so try the next item */
  121.                         if ((!foundPosition) && EqualString(fName, vFName, false, false)) {
  122.                             index++;
  123.                             foundPosition = true;
  124.                         }
  125.                     }
  126.                 }
  127.             }
  128.         }
  129.     }
  130.     
  131.     return(err);
  132. }
  133.  
  134. /*
  135.     This routine is called when the user chooses "Select File…" from the
  136.     File Menu.
  137.     
  138.     Currently it simply calls the new StandardGetFile routine to have the
  139.     user select a single file (any type, numTypes = -1) and then calls the
  140.     SendODOCToSelf routine in order to process it.  
  141.             
  142.     The reason we send an odoc to ourselves is two fold: 1) it keeps the code
  143.     cleaner as all file openings go through the same process, and 2) if events
  144.     are ever recordable, the right things happen (this is called Factoring!)
  145.  
  146.     Modification of this routine to only select certain types of files, selection
  147.     of multiple files, and/or handling of folder & disk selection is left 
  148.     as an exercise to the reader.
  149. */
  150. pascal void SelectFile (void)
  151. {
  152.     StandardFileReply    stdReply;
  153.     SFTypeList            theTypeList;
  154.     
  155.     // nope, only working with 'thng' files
  156.     theTypeList[0]='thng';
  157.     
  158.     StandardGetFile(NULL, 1, theTypeList, &stdReply);
  159.     if (stdReply.sfGood)    // user did not cancel
  160.         SendODOCToSelf(&stdReply.sfFile);    // so send me an event!
  161. }
  162.  
  163. /*
  164.     This routine is called during the program's initialization and gives you
  165.     a chance to allocate or initialize any of your own globals that your
  166.     dropbox needs.
  167.     
  168.     You return a boolean value which determines if you were successful.
  169.     Returning false will cause DropShell to exit immediately.
  170. */
  171. pascal Boolean InitUserGlobals(void)
  172. {
  173.     gAppResFile=CurResFile();
  174.     
  175.     return(true);    // nothing to do, it we must be successful!
  176. }
  177.  
  178. /*
  179.     This routine is called during the program's cleanup and gives you
  180.     a chance to deallocate any of your own globals that you allocated 
  181.     in the above routine.
  182. */
  183. pascal void DisposeUserGlobals(void)
  184. {
  185.     // nothing to do for our sample dropbox
  186. }
  187.